package com.gxa.controller;

import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.CarManageDTO;
import com.gxa.domain.dto.MaterialDTO;
import com.gxa.domain.entity.CarManage;
import com.gxa.domain.entity.Material;
import com.gxa.domain.vo.MaterialVO;
import com.gxa.service.CarManageService;
import com.gxa.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * User: gxb
 * Date: 2024/07/18  9:22
 * Description:
 * Version: V1.0
 */
@Api(tags = "库存管理-物料管理")
@RestController
@RequestMapping("/logistics/material")
@Slf4j
public class MaterialController {
    @Autowired
    private MaterialService materialService;

    //定义请求路径 并且请求方式限制为get
    @ApiOperation("查询物料列表")
    @GetMapping("/list")
    public RespResult list() {
        //1.查询所有物料
        List<MaterialVO> materialList = materialService.findMaterialAll();
        //2.返回给前端
        return RespResult.success(materialList);
    }
    @ApiOperation("根据id查找物料")
    @GetMapping("/find")
    public RespResult find(Long id) {//springmvc会自动进行参数绑定
        //调用service进行业务处理
        MaterialVO materialById = materialService.findMaterialById(id);
        //返回结果给前端
        return RespResult.success(materialById);
    }

    @ApiOperation("添加物料")
    @PostMapping("/add")
    public RespResult add(@RequestBody Material material) {//@RequestBody 前端给后端发送json数据
        materialService.insertMaterial(material);
        return RespResult.success();
    }

    @ApiOperation("修改物料信息")
    @PostMapping("/update")
    public RespResult update(@RequestBody Material material) {//@RequestBody 前端给后端发送json数据
        materialService.updateMaterial(material);
        return RespResult.success();
    }


    @ApiOperation("删除物料")
    @GetMapping("/delete")
    public RespResult delete(Long id) {//springmvc会自动进行参数绑定
        System.out.println("id:" + id);
        //调用service进行业务处理
        materialService.deleteMaterialById(id);
        System.out.println("------------");
        //返回结果给前端
        return RespResult.success();
    }

    @ApiOperation("条件查询")
    @GetMapping("/findMaterialByWhere")
    public RespResult list(MaterialDTO materialDTO) {
        //1.查询页面数据
        List<Material> materialList = materialService.findMaterialByWhere(materialDTO);
        System.out.println("------------");
        //2.返回给前端
        return RespResult.success(materialList);
    }

}
